package com.ewanghuiju.app.model.prefs;

import android.content.Context;
import android.content.SharedPreferences;

import com.ewanghuiju.app.app.App;
import com.ewanghuiju.app.app.Constants;

import javax.inject.Inject;

/**
 * @author sj  qq:751943509
 * @class describe
 * @time 2020/2/10
 */
public class ImplPreferencesHelper implements PreferencesHelper {

    private static final boolean DEFAULT_NO_IMAGE = false;

    private static final String SHAREDPREFERENCES_NAME = "my_sp";

    private final SharedPreferences mSPrefs;

    @Inject
    public ImplPreferencesHelper() {
        mSPrefs = App.getInstance().getSharedPreferences(SHAREDPREFERENCES_NAME, Context.MODE_PRIVATE);
    }

    @Override
    public boolean getNoImageState() {
        return mSPrefs.getBoolean(Constants.SP_NO_IMAGE, DEFAULT_NO_IMAGE);
    }

    @Override
    public String getLocalUserInfo() {
        return mSPrefs.getString(Constants.SP_USER_INFO, "");
    }

    @Override
    public void setLocalUserInfo(String str) {
        mSPrefs.edit().putString(Constants.SP_USER_INFO, str).apply();
    }

    @Override
    public String getToken() {
        return mSPrefs.getString(Constants.SP_TOKEN, "");
    }

    @Override
    public void setToken(String token) {
        mSPrefs.edit().putString(Constants.SP_TOKEN, token).apply();
    }

    @Override
    public boolean getIsAccepAgreement() {
        return mSPrefs.getBoolean(Constants.ACCEP_AGREEMENT, false);
    }

    @Override
    public void setIsAccepAgreement(boolean isAccep) {
        mSPrefs.edit().putBoolean(Constants.ACCEP_AGREEMENT, isAccep).apply();
    }

    @Override
    public boolean getIsFirst() {
        return mSPrefs.getBoolean(Constants.IS_FALSE, false);
    }

    @Override
    public void setIsFirst(boolean isFirst) {
        mSPrefs.edit().putBoolean(Constants.IS_FALSE, isFirst).apply();
    }

    @Override
    public void setIsAlias(boolean isAlias) {
        mSPrefs.edit().putBoolean(Constants.IS_ALIAS, isAlias).apply();
    }

    @Override
    public boolean getIsAlias() {
        return mSPrefs.getBoolean(Constants.IS_ALIAS, false);
    }
}

